<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <role-search @search="reload" />
      <!-- 数据表格 -->

      <ele-pro-table ref="table"
                     :columns="columns"
                     :datasource="datasource"
                     :selection.sync="selection"
                     tool-class="ele-toolbar-form"
                     row-key="id">
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>

        </template>
        <template v-slot:realName="{ row }">
          <div class="realNameStyle flex">
            <img class="avaterName"
                 :src="row.avatar"
                 alt="" />
            <div class="flex-column-start">
              <div style="width: 40px">{{ row.nickname }}</div>
            </div>
          </div>
        </template>
        <template v-slot:pay_mode="{ row }">
          <el-link v-if="row.pay_mode == 1"
                   type="success"
                   :underline="false"
                   @click="viewDetail(row)">
            微信
          </el-link>
          <el-link v-if="row.pay_mode == 2"
                   type="primary"
                   :underline="false"
                   @click="viewDetail(row)">
            支付宝
          </el-link>
        </template>
        <template v-slot:fees_ratio="{ row }">
          <div>
            {{ row.fees_ratio }}%
          </div>
        </template>
        <template v-slot:content="{ row }">
          <div v-html="row.content"></div>
        </template>
        <template v-slot:status="{ row }">
          <el-link :underline="false"
                   :type="informationType(row.status)?.types">
            {{ informationType(row.status).text }}
          </el-link>
        </template>
        <!-- 状态列 -->

        <template v-slot:discount_money="{ row }">
          <div>
            {{ row.discount_money }}
          </div>
        </template>
        <template v-slot:sort="{ row }">
          <i class="sort-handle el-icon-rank ele-text-secondary"
             style="cursor: move"></i>
          <div v-if="false">{{ row }}</div>
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link type="primary"
                   v-if="row.status != 4"
                   :underline="false"
                   icon="el-icon-document"
                   @click="openEdit(row)">
            提现审核
          </el-link>
          <el-link type="danger"
                   v-if="row.status == 4"
                   :underline="false"
                   icon="el-icon-document-delete"
                   @click="openEdit(row)">
            驳回原因
          </el-link>
          <!-- <el-popconfirm class="ele-action"
                         title="确定要删除该条信息？"
                         @confirm="remove(row)">
            <template v-slot:reference>
              <el-link type="danger"
                       :underline="false"
                       icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm> -->
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->
    <role-edit :data="current"
               :drawerEditBoolen.sync="drawerEditBoolen"
               @done="reload" />
    <!-- 权限分配弹窗 -->
  </div>
</template>
	
	<script>


import RoleSearch from './components/role-search';
// import Sortable from 'sortablejs';
import RoleEdit from './components/role-edit';
import { carouselList } from './constant/constant';
import { messageList } from '@/api/withdrawalManagement/index'


// import {
//   sitecCategoriesDelete,
//   siteCategoriesList,
//   siteCategoriesModify,
//   siteCategoriesDetail,
//   siteBatchCategoriesDelete
// } from '@/api/serviceManagement/categoriesList';
export default {
  name: 'Recharge',
  components: {
    RoleSearch,
    RoleEdit
  },
  data () {
    return {
      carouselList,
      // 表格列配置
      columns: [

        // {
        //   prop: 'id',
        //   label: '排序',
        //   sortable: 'custom',
        //   showOverflowTooltip: true,
        //   minWidth: 30,
        //   align: 'center',
        //   slot: 'sort'
        // },
        {
          columnKey: 'index',
          type: 'index',
          label: '序号',
          width: 60,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'realName',
          label: '用户',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 80,
          slot: 'realName'
        },

        {
          prop: 'sn_order',
          label: '提现单号',
          sortable: 'custom',
          align: 'center',
          resizable: false,
          showOverflowTooltip: false
        },
        {
          prop: 'reality_amount',
          label: '实际到账金额',
          sortable: 'custom',

          showOverflowTooltip: true,

          align: 'center'
        },
        {
          prop: 'fees_ratio',
          label: '提现手续费',
          sortable: 'custom',

          showOverflowTooltip: true,
          align: 'center',
          slot: 'fees_ratio'
        },
        {
          prop: 'fees',
          label: '提现手续费金额',
          sortable: 'custom',

          showOverflowTooltip: true,
          align: 'center',

        },
        {
          prop: 'pay_mode ',
          label: '提现方式',
          align: 'center',
          sortable: 'custom',

          showOverflowTooltip: true,
          slot: 'pay_mode'
        },
        {
          prop: 'status',
          label: '当前状态',
          align: 'center',
          sortable: 'custom',

          showOverflowTooltip: true,
          slot: 'status'
        },
        {
          prop: 'remark',
          label: '备注',
          sortable: 'custom',
          minWidth: 80,
          showOverflowTooltip: false,
          align: 'center',
          resizable: false,
        },

        {
          prop: 'create_time',
          label: '创建时间',
          resizable: false,
          align: 'center',
          sortable: 'custom',
          showOverflowTooltip: true,
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
          }
        },
        {
          columnKey: 'action',
          label: '操作',

          align: 'center',
          resizable: false,
          slot: 'action',

          showOverflowTooltip: true,
          fixed: 'right'
        }
      ],
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,

      // 是否显示编辑弹窗
      drawerEditBoolen: false,
      // 是否显示导入弹窗
      showAuth: false,
      showChoose: false
    };
  },
  mounted () {

  },
  activated () {
    this.reload();
  },
  computed: {
    // 1 待打款 2 打款中 3 已 完成 4 驳回',-->

    informationType () {
      return function (informationType) {

        if (informationType == 1) {
          return {
            text: '待打款',
            types: 'warning'
          };
        } else if (informationType == 2) {
          return {
            text: '打款中',
            types: 'info'
          };
        } else if (informationType == 3) {
          return {
            text: '已完成',
            types: 'success'
          };
        } else if (informationType == 4) {
          return {
            text: '已驳回',
            types: 'danger'
          };
        }
      };
    }
  },

  methods: {
    // rowDrop () {
    //   const tbody = document.querySelector('.el-table__body-wrapper tbody');
    //   const _this = this;
    //   Sortable.create(tbody, {
    //     forceFallback: true,
    //     dragClass: 'drag',
    //     delay: 100,
    //     animation: 1000,
    //     onEnd ({ newIndex, oldIndex }) {
    //       console.log(newIndex);
    //       console.log(oldIndex);
    //       //更换表格数据 后续拖动坐标才会正确
    //       let data = _this.$refs.table.getData();

    //       let nid = data[newIndex].id;
    //       let oid = data[oldIndex].id;

    //       const currRow = data.splice(oldIndex, 1)[0];
    //       data.splice(newIndex, 0, currRow);

    //       console.log(data);

    //       //   sortChange(data)
    //       //     .then((msg) => {

    //       //     })
    //       //     .catch((e) => {
    //       //       _this.$refs.table.reload();
    //       //     });

    //       //去数据库更换排序

    //       console.log(_this.$refs.table.getData());
    //     }
    //   });
    // },

    /* 表格数据源 */
    datasource ({ page, limit, where }) {
      return messageList({
        page,
        limit,
        ...where,

      });
    },
    /* 刷新表格 */
    reload (where) {
      this.$refs.table.reload({ page: 1, where: where });
    },
    /* 显示编辑 */
    async openEdit (row) {
      console.log(row);
      if (row?.id) {
        // const res = await siteCategoriesDetail(row.id);

        this.current = row;
        // 用户余额管理
        this.drawerEditBoolen = !this.drawerEditBoolen;
      } else {
        this.drawerEditBoolen = !this.drawerEditBoolen;
        this.current = null;
      }
    },



    /* 显示分配权限 */
    openAuth (row) {
      this.current = row;
      this.showAuth = true;
    },
    /* 删除 */
    // remove (row) {
    //   const loading = this.$loading({ lock: true });
    //   sitecCategoriesDelete(row.id)
    //     .then((msg) => {
    //       loading.close();
    //       this.$message.success(msg);
    //       this.reload();
    //     })
    //     .catch((e) => {
    //       loading.close();
    //       this.$message.error(e.message);
    //     });
    // },
    /* 批量删除 */
    // removeBatch () {
    //   if (!this.selection.length) {
    //     this.$message.error('请至少选择一条数据');
    //     return;
    //   }
    //   console.log(this.selection);
    //   this.$confirm('确定要删除选中的信息吗?', '提示', {
    //     type: 'warning'
    //   })
    //     .then(() => {
    //       const loading = this.$loading({ lock: true });
    //       console.log(this.selection.map((d) => d.id));
    //       siteBatchCategoriesDelete(this.selection.map((d) => d.id))
    //         .then((msg) => {
    //           loading.close();
    //           this.$message.success(msg);
    //           this.reload();
    //         })
    //         .catch((e) => {
    //           loading.close();
    //           this.$message.error(e.message);
    //         });
    //     })
    //     .catch(() => { });
    // }
  }
};
	</script>
	
	<style lang="less" scoped>
.realNameStyle {
  .avaterName {
    width: 41px;
    height: 41px;
    border-radius: 36px;
    vertical-align: middle;
    margin-right: 5px;
  }
  .technicianName {
    color: #1890ff;
    font-size: 12px;
    font-style: normal;
    font-weight: 400;
  }
}
.categoryImages {
  width: 50px;
  height: 50px;
}
</style>
	